/*
 * @Description: 
 * @Author: chenjiaxin
 * @Date: 2021-12-21 20:00:06
 * @LastEditTime: 2021-12-21 20:53:27
 * @FilePath: \novel-serve\src\app\database.js
 */
const mysql = require("mysql2");
const config = require("./config");

const connections = mysql.createPool({
  host: config.MYSQL_HOST, //数据库主机ip
  port: config.MYSQL_PORT, //数据库端口
  database: config.MYSQL_DATABASE, // mysql 的 数据库名称
  user: config.MYSQL_ROOT, // mysql 用户名
  password: config.MYSQL_PASSWORD, //mysql密码
});

connections.getConnection((err, conn) => {
  conn.connect((err) => {
    if (err) {
      console.log("连接失败：", err);
    } else {
      console.log("数据库连接成功~");
    }
  });
});

module.exports = connections.promise();